﻿/**
Library: transition managing library (TraM)
Author: Valentyn Derkach 2007.07.04
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Is the simplest transitioning engine. It is changing the values of the properties directly and that's the idea.
/**/

package com.bizmlib.tram
{
	import flash.events.Event;
	
	
	public class DirectTransform extends TraM
	{
		var currentProperties:Object;
		

		public function DirectTransform(subject:Object = undefined, properties:Object = undefined, engine:IEngine = undefined)
		{
			super(subject, properties, engine);
			setName("direct transformation");
		}
		
		
		override protected function setProperties(properties:Object = undefined):Boolean
		{
			var result:Boolean = super.setProperties(properties);
			
			if(result)
			{
				if(updateOnEnterFrame)
				{
					renderManager.start("render");
				}
				currentProperties = (properties ? new Object() : null);
			}
			
			return result;
		}
		// ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
		override protected function transitionIteration():void
		{
			//trace(this + ".transitionIteration(" + arguments + ")");
			
			for(var member in properties){
				var newValue:* = engine.performCalculation(String(member), subject[member], properties[member]);
				//subject[member] = engine.performCalculation(String(member), subject[member], properties[member]);
				if(updateOnEnterFrame)
				{
					currentProperties[member] = newValue;
					renderManager.start("render");
				}
				else
				{
					subject[member] = newValue;
				}
			}
		}
		// ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————
		
		override protected function doRender(event:Event):void
		{
			if(renderManager.checkProperty("render", true))
			{
				for(var member in currentProperties)
				{
					subject[member] = currentProperties[member];
				}
			}
		}
	}
}